package com.cn.bulu.utils.interceptorUtils;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.cn.bulu.dao.CustomerDao;
/**
 * 登录拦截器
 * @author wyw
 *
 */
public class CustomerLoginInterceptor extends HandlerInterceptorAdapter{
	@Resource
	private CustomerDao customerDao;
	//这个方法在业务处理器处理请求之前被调用
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		Object customerId = request.getSession().getAttribute("customerId");
		System.out.println("-------------------------------------------");
		System.out.println("我看看customerId="+customerId);
		if (customerId==null){
			response.sendRedirect("../interceptor/message");
			return false;
		}else{
			return true;
		}
		
		
	}
	//这个方法在业务处理器处理完请求后，但是DispatcherServlet向客户端返回请求前被调用，在该方法中对用户请求request进行处理。
	@Override
	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
			ModelAndView modelAndView) throws Exception {
		// TODO Auto-generated method stub
		super.postHandle(request, response, handler, modelAndView);
	}
	//这个方法在DispatcherServlet完全处理完请求后被调用，可以在该方法中进行一些资源清理的操作。
	@Override
	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
			throws Exception {
		// TODO Auto-generated method stub
		super.afterCompletion(request, response, handler, ex);
	}



	
	
	
}
